// const http = require('http');
// const server = http.createServer();

// server.on('request',(req,res)=>{
//     console.log(req.headers);
//     console.log('request received');
//     res.setHeader('Content-Type','text/html;charset=utf-8')
//     const url = req.url;
//     res.end("您请求的URL地址为"+url+"请求方式为"+req.method)
// })

// server.listen(50144,()=>{
//     console.log('server is listening');
// })



//导入http模块
const http = require('http');
//导入fs模块
const fs = require('fs')
//创建web服务器对象
const server = http.createServer();

//监听request请求 req是请求对象 res是响应对象
server.on('request', (req, res) => {
    //如果有访问 输出客户端请求头
    console.log(req.headers);
    //提示客户端请求已收到
    console.log('request received');
    //设置响应头编码格式
    res.setHeader('Content-Type', 'text/html;charset=utf-8')
    //判断并返回内容
    if (req.url === '/' || req.url === '/clock.html') {
        fs.readFile('http/clock.html', 'utf8', (err, data) => {
            if (err)
                console.log('clock 文件读取失败 ' + err)
            res.end(data)
        })
    } else if (req.url === '/about.html') {
        content = '<h1>关于我们</h1>'
    } else {
        content = '<h1>404 NOT FOND</h1>'
    }
})
//监听50144端口（苹果默认端口）win默认端口为8080、80
server.listen(50144, () => {
    console.log('server is listening');
})
